import static java.lang.System.out;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ValidateEmailAddress {

	public static void main(String[] args) {
		
		String emailRegEx = "\\w+@\\w+\\.[a-zA-Z]{2,4}";
		
		// Using String class matches
		out.println("noreply@temp.com".matches(emailRegEx)); // true
		out.println("info@abc".matches(emailRegEx)); // false
		
		// Using Pattern class matches
		out.println
			(Pattern.matches(emailRegEx, "noreply@temp.com"));//true
		out.println(Pattern.matches(emailRegEx, "info@abc"));// false
		
		// using Compiled RegEx
		Pattern p = Pattern.compile(emailRegEx);
		
		Matcher m = p.matcher("noreply@temp.com");
		out.println(m.matches()); // true
		
		m = p.matcher("info@abc");
		out.println(m.matches()); // false

	}

}
